<?php
	ini_set('date.timezone','Asia/Shanghai');
	header("content-type:text/html;charset=utf-8");

   	$mysql_conf = array(
        'host'    => '127.0.0.1', 
        'db'      => 'area', 
        'db_user' => 'root', 
        'db_pwd'  => 'root', 
    );

    $mysqli = @new mysqli($mysql_conf['host'],$mysql_conf['db_user'],$mysql_conf['db_pwd']);
	    if ($mysqli->connect_errno) {
	        die("could not connect to the database:\n" . $mysqli->connect_error);//诊断连接错误
	    }
	    $mysqli->query("set names 'utf8';");//编码转化
	    $select_db = $mysqli->select_db($mysql_conf['db']);
	    if (!$select_db) {
	        die("could not connect to the db:\n" .  $mysqli->error);
	    }

// $level = isset($_GET['level'])? $_GET['level'] : '';
$parent_region_code = isset($_GET['fatherid'])? $_GET['fatherid'] : '';

if($parent_region_code == ''){
    $sql ="SELECT * FROM region WHERE level = 1 ";
}else{
    $sql ="SELECT * FROM region WHERE parent_region_code='$parent_region_code' ";
}
$query = $mysqli->query($sql);

// print_r($query);
// $result= array();
while ($row = $query->fetch_array(MYSQLI_ASSOC)) {
    $result[] = $row;
}
//将数据解析成json格式的
var_dump($result);
// echo json_encode($result);

	//释放资源
	$query->close();
    $mysqli->close();



?>